﻿using System;
using System.Collections.Generic;
using System.ServiceModel;

namespace MSTestEx
{
    public static class InProcService<TContract, TImplementation>
    {
        private static readonly Dictionary<Type, ServiceHost> RegisteredHosts = new Dictionary<Type, ServiceHost>();

        public static TContract Create()
        {
            if (!RegisteredHosts.ContainsKey(typeof(TContract)))
            {
                var uri = new Uri("net.pipe://localhost/test");
                var serviceHost = new ServiceHost(typeof(TContract), new[] { uri });

                serviceHost.Open();

                RegisteredHosts[typeof(TContract)] = serviceHost;
            }

            return default(TContract);
        }
    }
}
